package com.example.myprojectoffeixue;
import android.app.Activity;
import android.app.Dialog;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.GridView;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.SimpleAdapter;
import android.widget.TextView;

import java.util.ArrayList;
import java.util.HashMap;

public class HouseActivity extends Activity {
    ArrayList<HashMap<String, Object>> lstItems = new ArrayList<HashMap<String, Object>>();
    SimpleAdapter imageItems;
    MyApplication m;
    int[] mainInterfaceImageIDs;
    String[] mainInterfaceStr;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_house);
        info();
    }

public void info(){
           m= (MyApplication) getApplication();
        LinearLayout tfinish = (LinearLayout) findViewById(R.id.iv_mykaiguan);
        tfinish.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            finish();
        }
        });


            GridView gd = (GridView) findViewById(R.id.gd_h);
            mainInterfaceImageIDs = new int[]{R.drawable.zw1, R.drawable.cw1, R.drawable.kt1, R.drawable.etf1, R.drawable.cf1, R.drawable.ct1
                    , R.drawable.wsj1, R.drawable.sf1, R.drawable.lt1, R.drawable.ys1, R.drawable.yt1, R.drawable.dmt1};
             mainInterfaceStr = new String[]{"主卧", "次卧", "客厅", "儿童房", "厨房", "餐厅", "卫生间", "书房", "楼梯", "浴室", "阳台", "多媒体房"};
            imageItems = new SimpleAdapter(HouseActivity.this, lstItems, R.layout.item_h, new String[]{"itemsImage", "itemsText"}, new int[]{R.id.itemImage, R.id.itemText});
            for (int j = 0; j < mainInterfaceImageIDs.length; j++) {
                if (mainInterfaceImageIDs[j] != 0) {
                    HashMap<String, Object> map = new HashMap<String, Object>();
                    map.put("itemsImage", mainInterfaceImageIDs[j]);
                    map.put("itemsText", mainInterfaceStr[j]);
                    lstItems.add(map);
                }
            }
            gd.setAdapter(imageItems);

            gd.setOnItemClickListener(new AdapterView.OnItemClickListener() {
                @Override
                public void onItemClick(AdapterView<?> parent, View view, int position, long id) {

                   // ImageView iv = (ImageView) view.findViewById(R.id.itemImage);
                    if (position == 0) {

                        m.name_house=mainInterfaceStr[0];



                    }else if(position==1){
                        m.name_house=mainInterfaceStr[1];


                        }else  if(position==2){
                        m.name_house=mainInterfaceStr[2];




                    }else  if(position==3){
                        m.name_house=mainInterfaceStr[3];

                    }else  if(position==4){

                        m.name_house=mainInterfaceStr[4];




                    }else  if(position==5){

                        m.name_house=mainInterfaceStr[5];


                    }else  if(position==6){

                        m.name_house=mainInterfaceStr[6];




                    }else  if(position==7){


                        m.name_house=mainInterfaceStr[7];


                    }else  if(position==8){
                        m.name_house=mainInterfaceStr[8];





                    }else  if(position==9){

                        m.name_house=mainInterfaceStr[9];



                    }else  if(position==10){

                        m.name_house=mainInterfaceStr[10];



                    }else  if(position==11){
                        m.name_house=mainInterfaceStr[11];

                    }
                    if(m.Nodevice_house!=null){
                     Intent it =new Intent(HouseActivity.this,ChoiceSbActivity.class);
                     startActivity(it);
                   }else{
                        HttpConnection.showToast(getBaseContext(),"不存在未分配的设备");
                    }

                }

            });

        }




}














